package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.EmpAdditionalFieldsAddDTO;
import org.jsola.hr.dto.EmpAdditionalFieldsUpdateDTO;
import org.jsola.hr.entity.EmpAdditionalFieldsDO;
import org.jsola.hr.query.EmpAdditionalFieldsQuery;
import org.jsola.hr.service.IEmpAdditionalFieldsService;
import org.jsola.hr.vo.EmpAdditionalFieldsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工额外字段信息表
 *
 * @author zhr
 */
@Component
public class EmpAdditionalFieldsTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpAdditionalFieldsService empAdditionalFieldsService;

    /**
     * 生成add测试数据
     * @return EmpAdditionalFieldsAddDTO
     */
    public EmpAdditionalFieldsAddDTO getEmpAdditionalFieldsAddDTO(){
        EmpAdditionalFieldsAddDTO empAdditionalFieldsAddDTO = new EmpAdditionalFieldsAddDTO();
        empAdditionalFieldsAddDTO.setModuleCode(getRandomValue("varchar",30));
        empAdditionalFieldsAddDTO.setFieldId(SafeKit.getLong(getRandomValue("bigint",11)));
        empAdditionalFieldsAddDTO.setCompanyId(getRandomValue("varchar",32));
        empAdditionalFieldsAddDTO.setEmpId(getRandomValue("varchar",32));
        empAdditionalFieldsAddDTO.setContent(getRandomValue("text",200000));
        empAdditionalFieldsAddDTO.setType(SafeKit.getInteger(getRandomValue("int",1)));
        return empAdditionalFieldsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpAdditionalFieldsUpdateDTO
     */
    public EmpAdditionalFieldsUpdateDTO getEmpAdditionalFieldsUpdateDTO(EmpAdditionalFieldsVO empAdditionalFieldsVO){
        return empAdditionalFieldsService.selectDOById(empAdditionalFieldsVO.getId(), SITE_ID).to(EmpAdditionalFieldsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpAdditionalFieldsQuery
     */
    public EmpAdditionalFieldsQuery getEmpAdditionalFieldsQuery() {
        EmpAdditionalFieldsQuery empAdditionalFieldsQuery = new EmpAdditionalFieldsQuery();
        List<EmpAdditionalFieldsDO> empAdditionalFieldsDOList = empAdditionalFieldsService.list(new EmpAdditionalFieldsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empAdditionalFieldsDOList)) {
            EmpAdditionalFieldsDO empAdditionalFieldsDO = empAdditionalFieldsDOList.get(0);
            empAdditionalFieldsQuery = empAdditionalFieldsDO.to(EmpAdditionalFieldsQuery.class);
        }
        return empAdditionalFieldsQuery;
    }

    /**
     * 保存示例
     * @return EmpAdditionalFieldsVO
     */
    public EmpAdditionalFieldsVO saveEmpAdditionalFieldsExample(){
        EmpAdditionalFieldsAddDTO addDTO = this.getEmpAdditionalFieldsAddDTO();
        EmpAdditionalFieldsVO empAdditionalFieldsVO = empAdditionalFieldsService.save(addDTO,buildTokenUser());
        return empAdditionalFieldsVO;
    }


}

